var order = {
	init:function(){
        this.layuiUse();	
        this.goOrder();
        this.goOrderBefore();
        this.goEditAddress();
	},
	layuiUse:function(){
		layui.use(['layer', 'form','jquery','flow'], function(){
            var layer = layui.layer,
            form = layui.form,
            $ = layui.$;

            //收货地址的判断
            if(GetCookie('address')){
                $('.addressUserName').html(GetCookie('addressUserName'));
                $('.addressUserPhone').html(GetCookie('addressUserPhone'));
                $('.address').html(GetCookie('address'));
                $('.hasAddress').removeClass('hide');
                $('.noAddress').addClass('hide');
            }else{
                $('.hasAddress').addClass('hide');
                $('.noAddress').removeClass('hide');
            }
        });
    },
    //提交订单前的准备
    goOrderBefore:function(){
        let isTokenNow = public.isToken();
        if(isTokenNow!=10000){
            layui.use(['layer'], function(){
                var layer = layui.layer;
                layer.msg('<p class="colorSystem font16 alignC mt15">请您先登录~</p>',{time:600},function(){
                    window.location.href="../../html/login/login.html";
                });
            });
        }else{
            $.ajax({
                type: 'post',
                url: link + '/mobile/order/ready',
                data: {
                    'token':GetCookie('token'),
                },
                dataType: 'json',
                success: function (res) {
                    console.log(res);
                    if(res.code==10000){
                        if(res.entity.accountActivation!=0){
                            $('.accountActivationBox').removeClass('hide');
                        }
                        if(res.entity.balanceActivation!=0){
                            $('.balanceActivationBox').removeClass('hide');
                        }
                        $('.accountActivation').html(res.entity.accountActivation.toFixed(2));
                        $('.balanceActivation').html(res.entity.balanceActivation.toFixed(2));
                        $('.notBalance').html(res.entity.notBalance.toFixed(2));
                        $('.sureBalance').html(res.entity.sureBalance.toFixed(2));
                        $('.totalPrice').html(res.entity.totalPrice.toFixed(2));
                    }
                },
                error: function (res) {
    
                },
            });
        }
        
    },
    //提交订单
    goOrder:function(){
        $('body').on('click','span[name="goOrder"]',function(){
			layer.msg('正在跳转支付页面~',{time:600},function(){
                $.ajax({
                    type: 'post',
                    url: link + '/mobile/order/create',
                    data: {
                        'token':GetCookie('token'),
                        'consignee':GetCookie('addressUserName'),
                        'consigneeMobile':GetCookie('addressUserPhone'),
                        'address':GetCookie('address')
                    },
                    dataType: 'json',
                    success: function (res) {
                        if(res.code==10000){
                            window.location.href=res.entity;
                        }else{
                            layer.msg(res.message);
                        }
                    },
                    error: function (res) {
        
                    },
                });
            });
		});
    },
    goEditAddress:function(){
        $('body').on('click','.goEditAddress',function(){
            window.location.href="/html/person/address.html";
        });
    }
}
order.init();

          